<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="(val,index) in pages" :key="index">
        <div v-for="item in val" :key="item.id">
          <div class="icon">
            <img class="icon-img" :src="item.imgUrl" alt="">
            <span>{{item.desc}}</span>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--lang="stylus"表示用stylus编写css样式-->
<!--计算宽高比列得出padding-bottom的值-->
<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    height: 0
    padding-bottom: 50%
  .icons
    overflow: hidden
    height: 0
    width:100%
    padding-bottom: 50%
    .icon
      float: left
      overflow: hidden
      width: 25%
      padding-bottom: .15rem
      text-align center
      .icon-img
        display: block
        box-sizing: border-box
        width: 50%
        padding-top .3rem
        padding-bottom .2rem
        margin: 0 auto
      span
        display: block
        padding: 0 .1rem
        color: $darkTextColor
        ellipsis()
</style>
